package one.stand.util;

import org.apache.http.util.TextUtils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;

/**
 * @author: QIK
 * @CreateDate: 2019/4/15 17:09
 */
public class DateUtil {
    private static Map<Integer ,String>  monthMap=new HashMap<Integer, String>(0){{
        put(1,"January");
        put(2,"February");
        put(3,"March");
        put(4,"April");
        put(5,"May");
        put(6,"June");
        put(7,"July");
        put(8,"August");
        put(9,"Sept");
        put(10,"October");
        put(11,"November");
        put(12,"December");
    }};

    /**
     * 当前日
     * @return
     */
    public static String currentDay(){
        Calendar cal = Calendar.getInstance();
        Integer day=cal.get(Calendar.DATE);
        if(day<10){
            return "0"+day;
        }
        return day+"";
    }

    /**
     * 当前月
     * @return
     */
    public static String currentMonth(){
        Calendar cal = Calendar.getInstance();
        Integer month=cal.get(Calendar.MONTH) + 1;
        return monthMap.get(month);
    }

    /**
     * 当前年
     * @return
     */
    public static String currentYear(){
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.YEAR)+"";
    }

    /**
     * 获取两个时间相差的秒数
     * @param date1
     * @param date2
     * @return
     */
    public static Long getDifferTime(Date date1,Date date2){
        long time1 = date1.getTime();
        long time2 = date2.getTime();
        return time1-time2;
    }


    /**
     * 获取当前时间
     * @return
     */
    public static Date now(){
        LocalDateTime localDateTime = LocalDateTime.now();
        return Date.from( localDateTime.atZone( ZoneId.systemDefault()).toInstant());
    }

    /**
     * 获取当天毫秒值
     * @return
     */
    public static long getStartTimeOfDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTimeInMillis();
    }

}
